package com.fit.pages;


import java.util.Date;
import java.util.Random;

import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Persist;

public class ACar {
	
	//------------------------------------
	@Persist
	private String passedUserName;
	//-----------------------------------

	@Persist
	private int numberOfChassis;
	@Persist
	private String nameOfCompany;
	@Persist
	private String modelName;
	@Persist
	private Date yearOfProducts;
	@Persist
	private String typeOfCar;
	@Persist
	private int enginePowerOfCar;
	@Persist
	private String colorOfCar;
	//----------------------------------------------------
	@Persist
	private boolean subscribe;
	
	private boolean unsubscribe;
	
	//---------------------------------------------------------
	@InjectPage
	private VCar viewCar;
	//------------------------------------------------------
	
	public boolean isSubscribe() {
		return subscribe;
	}
	public void setSubscribe(boolean subscribe) {
		this.subscribe = subscribe;
	}
	
	public boolean isUnsubscribe() {
		return unsubscribe;
	}
	public void setUnsubscribe(boolean unsubscribe) {
		this.unsubscribe = unsubscribe;
	}
	//-------------------------------------------------
	
	public String getPassedUserName() {
		return passedUserName;
	}
	public void setPassedUserName(String passedUserName) {
		this.passedUserName = passedUserName;
	}
	
	//--------------------------------------------------
	public int getNumberOfChassis() {
		
		return numberOfChassis;
	}
	
	public void setNumberOfChassis(int numberOfChassis) {
		numberOfChassis = new Random().nextInt();
		this.numberOfChassis = numberOfChassis;
	}
	public int getEnginePowerOfCar() {
		return enginePowerOfCar;
	}
	public void setEnginePowerOfCar(int enginePowerOfCar) {
		this.enginePowerOfCar = enginePowerOfCar;
	}
	public String getColorOfCar() {
		return colorOfCar;
	}
	public void setColorOfCar(String colorOfCar) {
		this.colorOfCar = colorOfCar;
	}
	public String getModelName() {
		return modelName;
	}
	public void setModelName(String modelName) {
		this.modelName = modelName;
	}
	public String getTypeOfCar() {
		return typeOfCar;
	}
	public void setTypeOfCar(String typeOfCar) {
		this.typeOfCar = typeOfCar;
	}
	public String getNameOfCompany() {
		return nameOfCompany;
	}
	public void setNameOfCompany(String nameOfCompany) {
		this.nameOfCompany = nameOfCompany;
		//System.out.println("setovano u add car"+this.nameOfCompany);
	}
	public Date getYearOfProducts() {
		return yearOfProducts;
	}
	public void setYearOfProducts(Date yearOfProducts) {
		this.yearOfProducts = yearOfProducts;
	}
	
	
	
	@OnEvent(value="sumbit", component = "userInputForm")
	Object onFormSubmit(){
		//System.out.println("car name is prossed...");
		viewCar.setPassedNumberOfChassis(numberOfChassis);
		viewCar.setPassedNameOfCompany(this.nameOfCompany);
		viewCar.setPassedModelName(modelName);
		viewCar.setPassedYearOfProducts(yearOfProducts);
		return viewCar;
	}
	@OnEvent(component = "goToViewcar")
	Object onLink(){
		viewCar.setPassedNumberOfChassis(numberOfChassis);
		viewCar.setPassedNameOfCompany(nameOfCompany);
		viewCar.setPassedModelName(modelName);
		viewCar.setPassedYearOfProducts(yearOfProducts);
		return viewCar;
	}
	@OnEvent(component="forma")
	void onSubscribe(){
		if(unsubscribe)
			subscribe = false;
	}
	@OnEvent(value="submit", component="ConfirmAction")
	Object onSubmitButton(){
		System.out.println("update action is passed:"+typeOfCar);
		viewCar.setPassedTypeOfCar(typeOfCar);
		viewCar.setPassedEnginePowerOfCar(enginePowerOfCar);
		viewCar.setPassedColorOfCar(colorOfCar);
		return null;
	}
	@OnEvent(component="UpdateAction")
	Object onSubmitButton2(){
		//System.out.println("update action is passed:"+typeOfCar);
		viewCar.setPassedTypeOfCar(typeOfCar);
		viewCar.setPassedEnginePowerOfCar(enginePowerOfCar);
		viewCar.setPassedColorOfCar(colorOfCar);
		return viewCar;
	}
}
